package pers.qianyu.handler;

import com.baomidou.mybatisplus.core.handlers.*;
import org.apache.ibatis.reflection.*;
import org.springframework.stereotype.*;

import java.time.*;

/**
 * 主句库字段自动填充处理器
 *
 * @author mizzle rain
 * @date 2020-10-12 9:52
 */
@Component
public class CommonMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Long.class, System.currentTimeMillis());
        this.strictInsertFill(metaObject, "updateTime", Long.class, System.currentTimeMillis());
        //this.strictInsertFill(metaObject, "createdBy", String.class, "TODO 从上下文获取创建者");
        //this.strictInsertFill(metaObject, "updatedBy", String.class, "TODO 从上下文获取更新者");
        this.strictInsertFill(metaObject, "deleted", Integer.class, 0);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        //this.strictUpdateFill(metaObject, "updatedBy", String.class, "TODO 最后更新者");
    }
}
